package com.example.demo01.Controller.webController;

import com.alibaba.fastjson.JSON;
import com.example.demo01.Entity.webEntity.NameValue;
import com.example.demo01.Service.webService.NameValueService;
import com.example.demo01.utils.DateParseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class NameValueController {
    //自动装配
    @Autowired
    private NameValueService nameValueService;

    /**
     * 获取每一个护理等级对应的人数
     * */
    @RequestMapping(value = "/namevalue/GET/piedata")
    public String staticByNurseLevel(){
        List<NameValue> nameValues = nameValueService.staticByNurseLevel();
        System.out.println(nameValues);
        String jsonString = JSON.toJSONString(nameValues);
        System.out.println(jsonString);
        return jsonString;
    }


    /**
     * 按照省份代码统计人数
     * */
    @RequestMapping(value = "/namevalue/GET/bardata/12")
    public String staticByProvinceCode(){
        return JSON.toJSONString(nameValueService.staticByProvinceCode());
    }

    /**
     * 按照城市代码统计人数
     * */
    @RequestMapping(value = "/namevalue/GET/bardata/34")
    public String staticByCityCode(){
        return JSON.toJSONString(nameValueService.staticByCityCode());
    }

    /**
     * 按照县区代码统计人数
     * */
    @RequestMapping(value = "/namevalue/GET/bardata/56")
    public String staticByCountryCode(){
        return JSON.toJSONString(nameValueService.staticByCountryCode());
    }

    /**
     * 获取每一个护理等级对应的历史报警次数
     * */
    @RequestMapping(value = "/namevalue/GET/rosedata/nurselevel")
    public String staticByNurseLevelforRose(){ return JSON.toJSONString(nameValueService.staticByNurseLevelforRose());}

    /**
     * 按照省份代码统计历史报警次数
     * */
    @RequestMapping(value = "/namevalue/GET/rosedata/12")
    public String staticByProvinceCodeforRose(){ return JSON.toJSONString(nameValueService.staticByProvinceCodeforRose());}

    /**
     * 按照城市代码统计历史报警次数
     * */
    @RequestMapping(value = "/namevalue/GET/rosedata/34")
    public String staticByCityCodeforRose(){ return JSON.toJSONString(nameValueService.staticByCityCodeforRose()); }

    /**
     * 按照县区代码统计历史报警次数
     * */
    @RequestMapping(value = "/namevalue/GET/rosedata/56")
    public String staticByCountryCodeforRose(){ return JSON.toJSONString(nameValueService.staticByCountryCodeforRose()); }


    /**
     * 获取每一个护理等级在特定时间区间内的报警次数
     * */
    @RequestMapping(value = "/namevalue/GET/rosedata/timelimit")
    public String staticByNurseLevelforRose(@RequestParam(value = "starttime") Long startTime,
                                            @RequestParam(value = "endtime") Long endTime)
    {
        return  JSON.toJSONString(nameValueService.staticByNurseLevelforRose(startTime,endTime));
    }


    /**
     * 按照省份和起止时间统计报警次数
     * @param startTime 起始时间
     * @param endTime 结束时间
     * */
    @RequestMapping(value = "/namevalue/GET/rosedata/12/timelimit")
    public String staticByProvinceCodeforRose(
            @RequestParam(value = "starttime") Long startTime,
            @RequestParam(value = "endtime") Long endTime)
    {
        System.out.println(startTime);
        System.out.println(DateParseUtils.getDateStrByFormat(DateParseUtils.millionsToUtilDate(startTime),"yyyy-MM-dd HH:mm:ss"));
        System.out.println(endTime);
        System.out.println(DateParseUtils.getDateStrByFormat(DateParseUtils.millionsToUtilDate(endTime),"yyyy-MM-dd HH:mm:ss"));
        return JSON.toJSONString(nameValueService.staticByProvinceCodeforRose(startTime,endTime));
    }

    /**
     * 按照城市代码统计历史报警次数
     * @param startTime 起始时间
     * @param endTime 结束时间
     * */
    @RequestMapping(value = "/namevalue/GET/rosedata/34/timelimit")
    public String staticByCityCodeforRose(
            @RequestParam(value = "starttime") Long startTime,
            @RequestParam(value = "endtime") Long endTime)
    {
        return JSON.toJSONString(nameValueService.staticByCityCodeforRose(startTime,endTime));
    }

    /**
     * 按照县区代码统计历史报警次数
     * @param startTime 起始时间
     * @param endTime 结束时间
     * */
    @RequestMapping(value = "/namevalue/GET/rosedata/56/timelimit")
    public String staticByCountryCodeforRose(
            @RequestParam(value = "starttime") Long startTime,
            @RequestParam(value = "endtime") Long endTime)
    {
        return JSON.toJSONString(nameValueService.staticByCountryCodeforRose(startTime,endTime));
    }

    /**
     * 根据idNum，按月份统计报警信息及其报警次数
     * @param idnum 身份证号
     * */
    @RequestMapping("/namevale/GET/warntime/month")
    public  String getNVWeightByIdNumUnderMonth(
            @RequestParam(value = "idnum") String idnum
    ){ return JSON.toJSONString(nameValueService.getNVWeightByIdNumUnderMonth(idnum)); }

    /**
     * 根据idnum，统计object的历史报警时刻
     * @param idnum 身份证号
     * */
    @RequestMapping("/namevale/GET/warntime/detail")
    public String getWarnTimeListByIdNum(
            @RequestParam(value = "idnum") String idnum
    )
    {
        return JSON.toJSONString(nameValueService.getWarnTimeListByIdNum(idnum));
    }

}
